Arguments - Positional

Sometimes it makes no sense to come up with a keyword for an argument.  Perhaps for convenience or perhaps because it makes the message read better.  In these cases you can have an argument that doesn’t correspond to a keyword.  They are called positional arguments, because their position in the message makes a difference.  (Recall that keyword arguments can be written in any order).

Suppose we want a new message for cash-register to read:

cash-register price-item "eggs".

One could argue that this reads better than adding a keyword before the "eggs" argument, like:

cash-register price-item name "eggs"

To use an argument that has no keyword, the script declares the argument with a dash in place of the keyword.  (Think of the dash meaning that the keyword is omitted.)  The script for the price-item message is:

$ - item-name.

switch item-name;

case "milk" do [ return 1.59 ];

case "eggs" do [ return 0.205 ];

case "cheese" do [ return 5.45 ].

return ???.

Positional Arguments and Style

Only use positional arguments when there is no other way to make a message read nicely.  While several predefined messages use positional arguments, we have found it rare that a user created message needs to use them.  In fact, even the message above could have been renamed so as to read better with a keyword argument:

cash-register price item "eggs"

Note the subtle difference: the name of message has been split and the last word used as keyword for the argument.  Unless there is a conflict with using the ‘price’ as a message name, this is a better solution.  A common mistake of style is to include too many words in the message name.  Programmers familiar with other languages are likely to make this error, as other languages don’t have keywords and all descriptive text must become part of the name of the function or procedure.

»
The above script returns the value ??? (unknown) when it doesn’t know what the answer is.  This is better programming style than not returning anything in this case.  If the script that sent this message can’t handle the ??? value, an error will occur.  But if the script wants handle this condition, then it is a simple matter for it to test for the value ???.